package com.chezhujie.www.controller;


import com.alibaba.fastjson.JSONObject;
import com.chezhujie.www.core.StaticMap;
import com.chezhujie.www.domain.*;
import com.chezhujie.www.domain.vo.AvoidAndSuit;
import com.chezhujie.www.domain.vo.CalActMonth;
import com.chezhujie.www.domain.vo.CalSeasonVO;
import com.chezhujie.www.domain.vo.CalTop3;
import com.chezhujie.www.domain.vo.CzjseasonVO1;
import com.chezhujie.www.domain.vo.DayAvoidAndSuit;
import com.chezhujie.www.service.*;
import com.chezhujie.www.utils.ConvertObj;
import com.chezhujie.www.utils.HttpRequest;
import com.chezhujie.www.utils.MapManage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/cal")
public class  CzjcalController extends BaseController{
	private static final Logger log = LoggerFactory.getLogger(CzjcalController.class);
		
	public CzjcalController() {
	}
	
	/**
	 * czj_advertisementImg  图片广告详情
	 * 
	 * @param userid
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("queryImgOrder.do")
	public void detail1111(String username, String userid, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception{
      try {
      		Map<String, Object> param = new HashMap<String, Object>();
      		param.put("username", username);     		
            Tsuser user = tuserService.getTuserByName(param);
                          
            //插入时
      		if("".equals(userid)){  
      			     if(user !=null){
      			    	jsonResult(1,"","重复的顺序",0,response);  
      			     }else{
      			    	jsonResult(1,"","可以添加",1,response);  
      			     }      				      			         
	      		}
      		//更新时      		
      		if(!"".equals(userid)){
          		//查询自己
          		Map<String, Object> paramMy = new HashMap<String, Object>();
          		paramMy.put("userid", userid);
          		Tsuser myorder = tuserService.getTuser(paramMy);
                String myordernum = myorder.getUsername();
                //和自己相同的可以更新
                if(myordernum.equals(username)){
                	jsonResult(1,"","可以添加",1,response); 
                }else{
                  //如果跟自己的不相同
                	List<String> listString = tuserService.getTuserALLName();
                	System.out.println(listString);
                	boolean flag = true;
                	//循环数据库字段,如果相同,就代表有重复
                	for(String str : listString){
                		if(username.equals(str)){
                			flag= false;
                		}
                	}
                	System.out.println(flag);
                	if(!flag){
                		jsonResult(1,"","重复的顺序",0,response); 
                	}else{
                		jsonResult(1,"","可以添加",1,response); 
                	}
                	
                	
                }                                             
      		}        		     		     		    		
            } catch (Exception e) {
            jsonResult(1,"","系统异常","",response);
   			log.error("czjadvertisementimg detail error:", e); 
            throw e;
   		  }
		
	}		
	
 	/**
	 * 用户表新增页面
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("tuserPer.do")
	public String tuserPer(HttpServletRequest request, ModelMap model) {
		return "sys/per";
	}	
	
	/**
	 * 用户表保存
	 * 
	 * @param tuser
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("tuserSave.do")
	public String save(Tsuser tuser, String username,
			String oldpas,String newpas,
			String userid,
			HttpServletRequest request,
			HttpServletResponse response,
			ModelMap model) throws Exception{				    
		try {
			//模型
	   		Map<String, Object> param2 = new HashMap<String, Object>();
	   		param2.put("userid", userid);
	         Tsuser tuser2 = tuserService.getTuser(param2);
	   		model.addAttribute("tuser", tuser2);
			
			
			//设置消息
			 String message = null;			
			//检查密码是否正确
	        Map<String, Object> param = new HashMap<String, Object>();
	        param.put("username", username);
			Tsuser  tuser1 = tuserService.getTuserByName(param);
	        if(tuser1!=null){
	          String oldpass = tuser1.getPasswd();
	          if(!oldpass.equals(oldpas)){
	        	  message ="0"; 
	          }else{
	        
			if(tuser.getUserid()!=null&&!tuser.getUserid().equals("")){
				// 编辑
				tuser.setPasswd(newpas);
				tuserService.updateTuser(tuser);
				message ="1"; 
				//tlogService.insertTloger(LoggerHelper.getTloger(request, LoggerHelper.OPERATING, "编辑用户表", "userid="+tuser.getUserid()));
			  }
	        }
	          request.setAttribute("message", message);
	     }
			
   		} catch (Exception e) {
   			log.error("tuser save error:", e); 
            throw e;
   		}
		    return "sys/editPass";	
	}	
	
 	/**
	 * 用户表新增页面
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("editPass.do")
	public String edit(String userid, HttpServletRequest request, ModelMap model) throws Exception{
	      try {
	   		Map<String, Object> param = new HashMap<String, Object>();
	   		param.put("userid", userid);
	         Tsuser tuser = tuserService.getTuser(param);
	   		model.addAttribute("tuser", tuser);
	         } catch (Exception e) {
	   			log.error("tuser edit error:", e); 
	            throw e;
	   		}
			return "sys/editPass";
		}	
	
	
	
	/**
	 * 日历前三名展示
	 * 
	 * @param czjfestivalact
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("czjcalSave.do")
	public String czjcalSave(Czjfestivalact czjfestivalact, String pageNo,
			HttpServletRequest request, ModelMap model) throws Exception{    
		try {
			if(czjfestivalact.getFestivalActId()!=null&&!czjfestivalact.getFestivalActId().equals("")){
				// 编辑				
				czjcalService.updateFestivalAct(czjfestivalact);
				 
				String  message =null;
				
				if("1".equals(czjfestivalact.getExt1())){	
					message = "1";
				}
				if("0".equals(czjfestivalact.getExt1())){	
					message = "0";
				}				
				model.addAttribute("message",message);
				//tlogService.insertTloger(LoggerHelper.getTloger(request, LoggerHelper.OPERATING, "编辑czj_discount  优惠", "discountId="+czjdiscount.getDiscountId()));
			} else {
				// 新增
/*				czjdiscount.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
				czjdiscountService.insertCzjdiscount(czjdiscount);*/
				//tlogService.insertTloger(LoggerHelper.getTloger(request, LoggerHelper.OPERATING, "新增czj_discount  优惠", "discountId="+czjdiscount.getDiscountId()));
			}
   		} catch (Exception e) {
   			log.error("czjfestivalact save error:", e); 
            throw e;
   		}
      
		return "redirect:/festivalact/list?pageNo="+pageNo;
	}		
	
	/**
	 * 日历前三名展示
	 * 
	 * @param czjfestivalact
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("czjcalSaveext5.do")
	public String czjcalSaveext5(Czjfestivalact czjfestivalact, String pageNo,
			HttpServletRequest request, ModelMap model) throws Exception{    
		try {
			if(czjfestivalact.getFestivalActId()!=null&&!czjfestivalact.getFestivalActId().equals("")){
				// 编辑		
				
				czjcalService.updateFestivalActExt5();
				
				czjcalService.updateFestivalAct(czjfestivalact);
				 
				String  message =null;
				
				if("1".equals(czjfestivalact.getExt1())){	
					message = "1";
				}
				if("0".equals(czjfestivalact.getExt1())){	
					message = "0";
				}				
				model.addAttribute("message",message);
				//tlogService.insertTloger(LoggerHelper.getTloger(request, LoggerHelper.OPERATING, "编辑czj_discount  优惠", "discountId="+czjdiscount.getDiscountId()));
			} else {
				// 新增
/*				czjdiscount.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
				czjdiscountService.insertCzjdiscount(czjdiscount);*/
				//tlogService.insertTloger(LoggerHelper.getTloger(request, LoggerHelper.OPERATING, "新增czj_discount  优惠", "discountId="+czjdiscount.getDiscountId()));
			}
   		} catch (Exception e) {
   			log.error("czjfestivalact save error:", e); 
            throw e;
   		}
      
		return "redirect:/festivalact/list?pageNo="+pageNo;
	}		
	
	
     /***
      * 
      * @author 
      * @date 2017年5月27日 下午2:11:56
      * @param request
      * @param response
      * @param model
      */
	@RequestMapping("discountList.do")
	public void detail1gag( HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("ext1",1 );
			List<Czjdiscount>  list = czjdiscountService.getCzjdiscountListALL(param);		
			List<Map<String,Object>> listmap = ConvertObj.toListMap(list);
			MapManage.returnReservedForListMap(listmap, new String[]{"imgUrl","imgPath","remark","ext2"});
			jsonResult(1,"","获取假日优惠图片信息成功",listmap,response);
						
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"208","获取假日优惠图片信息错误,系统异常","",response);
			log.error("获取假日优惠图片信息错误,系统异常",e);
			
		}
		
	}		
 
    /***
     * 
     * @author 
     * @date 2017年5月27日 下午2:11:56
     * @param request
     * @param response
     * @param model
     */
	@RequestMapping("caltop3.do")
	public void detail1caltop3( HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("today",new SimpleDateFormat("yyyy-MM-dd").format(new Date()) );
			List<CalTop3>  list = czjcalService.getCalTop3(param);
			for(CalTop3 calTop3 :list){
				if(calTop3.getBeginTime()==null){
					calTop3.setBeginTime(calTop3.getExt2());
				}
				if(calTop3.getFestUrl()!=null){
					calTop3.setImgUrl(calTop3.getFestUrl());
				}
			}			
			jsonResult(1,"","获取假日活动前三名信息成功",list,response);
						
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"208","获取假日活动前三名信息错误,系统异常","",response);
			log.error("获取假日活动前三名信息错误,系统异常",e);
			
		}
		
	}	
	
    /***
     * 
     * @author 
     * @date 2017年5月27日 下午2:11:56
     * @param request
     * @param response
     * @param model
     */
	@RequestMapping("calMonth.do")
	public void detail1calMonth( HttpServletRequest request,
			@RequestParam(required=true) String month,		
			HttpServletResponse response, ModelMap model) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("month",month);
			List<CalActMonth>  calActMonths = czjcalService.getCalListMonth(param);	
			for(CalActMonth actMonth: calActMonths){
				if(actMonth.getFestUrl()!=null){
					actMonth.setImgUrl(actMonth.getFestUrl());
				}
			}
			List<CalActMonth> calSeasons  = czjcalService.getCalSeasonListMonth(param);
			 			
			//寻找相同的坐标 并且删除对应的坐标
			for(int i = 0 ; i<calActMonths.size();i++ ){
				for (int j = calSeasons.size() - 1; j >= 0; j--) {
				   String actnum = calActMonths.get(i).getNum();
				   String seanum = calSeasons.get(j).getNum();				   
				   if(actnum.equals(seanum)){
					   calActMonths.get(i).setRemark(calSeasons.get(j).getRemark());
					   calActMonths.get(i).setSeasonId(calSeasons.get(j).getSeasonId());
					   calSeasons.remove(j);
				   }										
				}
			}
			
			//加入不相同的
			calActMonths.addAll(calSeasons);
			

			
			
//			
//			
//			List<Map<String,Object>> listmap = new ArrayList<Map<String,Object>>();
//			
//			for(CalActMonth cala:calActMonths){
//				
//				Map<String,Object> map = ConvertObj.toMap(cala);
//				map.put("bs", 0);
//				
//				listmap.add(map);
//			}
//			
//			for(CalSeasonVO cala:calSeasons){
//				
//				Map<String,Object> map = ConvertObj.toMap(cala);
//				map.put("bs", 1);
//				
//				listmap.add(map);
//			}
			
			
			
			
			
//			Map<String, Object> resultMap = new HashMap<String, Object>();
//			resultMap.put("calActMonths", calActMonths);
//			resultMap.put("calSeasons", calSeasons);			
			jsonResult(1,"","获取一个月活动信息成功",calActMonths,response);
						
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"208","获取一个月活动信息错误,系统异常","",response);
			log.error("获取一个月活动信息错误,系统异常",e);
			
		}
		
	}
	
    /***
     * 
     * @author 
     * @date 2017年5月27日 下午2:11:56
     * @param request
     * @param response
     * @param model
     */
	@RequestMapping("seasonDetail.do")
	public void detailSeason( HttpServletRequest request,
			@RequestParam(required=true) String seasonId,		
			HttpServletResponse response, ModelMap model) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("seasonId", seasonId);
			CzjseasonVO1 czjseasonVO1 =  czjseasonService.getCzjseasonVO1(param);			
			jsonResult(1,"","获取节气信息成功",czjseasonVO1,response);
						
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"208","获取节气信息错误,系统异常","",response);
			log.error("获取节气信息错误,系统异常",e);
			
		}
		
	}	
	
	/**
	 * 广告轮播
	 * 
	 * @param voteId
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("advertisementList.do")
	public void detail1233dsf( HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("ext1",1 );
			List<Czjadvertisementimg>  list = czjadvertisementimgService.getCzjadvertisementimgListALL(param);
			
			List<Map<String,Object>> listmap = ConvertObj.toListMap(list);
			MapManage.returnReservedForListMap(listmap, new String[]{"imgUrl","imgPath","ext2"});
			jsonResult(1,"","获取广告列表信息成功",listmap,response);
						
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"204","获取广告列表信息错误,系统异常","",response);
			log.error("获取广告列表信息错误,系统异常",e);
			
		}
		
	}
	/**
	 * 广告轮播
	 *
	 * @param voteId
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("advertisementList2.do")
	public void detail1233dsf2( HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		try {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("ext1",1 );
			List<Czjadvertisementimg2>  list = czjadvertisementimg2Service.getCzjadvertisementimgListALL(param);

			List<Map<String,Object>> listmap = ConvertObj.toListMap(list);
			MapManage.returnReservedForListMap(listmap, new String[]{"imgUrl","imgPath","ext2"});
			jsonResult(1,"","获取广告列表信息成功",listmap,response);

		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"204","获取广告列表信息错误,系统异常","",response);
			log.error("获取广告列表信息错误,系统异常",e);

		}

	}


	/***
     * 
     * @author 
     * @date 2017年5月27日 下午2:11:56
     * @param request
     * @param response
     * @param model
     */
	@RequestMapping("TodayAvoidAndSuit.do")
	public void detailAvoid( HttpServletRequest request, 
			 String cityname,
			HttpServletResponse response, ModelMap model) {
		try {
            AvoidAndSuit avoidAndSuit = new AvoidAndSuit();
		    String strDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		    String todayString = strDate;
		    
			  String str= strDate.substring(0,4);			  
			  String strlast= strDate.substring(4,strDate.length());
			  strlast = strlast.replaceAll("0", "");
			  strDate = str+strlast;		    
		    //发送 GET 请求
			  String key = StaticMap.calendarKey;
		    String s= null;
		    Map<String,Object> map = null;
		    Map<String,Object> map1 = null;
		    Map<String,Object> map2 = null;
		    String avoid= null;
		    String suit = null;
		    String weekday = null;
		    
		    //限制查询忌宜次数一天一次
		    Map<String, Object> paramTquerylimit = new HashMap<String, Object>();
		    paramTquerylimit.put("today", todayString);
		    paramTquerylimit.put("type", "忌宜");
		    Tquerylimit tquerylimit = czjcalService.getTquerylimitByToday(paramTquerylimit);
		    if(tquerylimit!=null){
		    	avoid = tquerylimit.getExt2();
		    	suit = tquerylimit.getExt3();
		    }else{		    		    
		     try {
		       s=HttpRequest.sendGet("http://v.juhe.cn/calendar/day", "date="+strDate+"&key="+key);	
		       map = JSONObject.parseObject(s, Map.class);				
		       map1 = (Map<String,Object>)map.get("result");
		       map2 = (Map<String,Object>)map1.get("data");
		       avoid =  (String) map2.get("avoid");
		       suit =  (String) map2.get("suit");
		       weekday = (String) map2.get("weekday");
			} catch (Exception e) {
				avoid ="动土.破土.安葬.治病.";
				suit = "开市.纳财.祭祀.塑绘.安机械.冠笄.会亲友.裁衣.开仓.经络.纳畜.造畜椆栖.教牛马.牧养.";
				weekday ="星期一";
			}	  
		     tquerylimit = new Tquerylimit();
		     tquerylimit.setExt2(avoid);
		     tquerylimit.setExt3(suit);
		     tquerylimit.setExt4(weekday);
		     tquerylimit.setCreatetime(new Date());
		     tquerylimit.setType("忌宜");
		     tquerylimit.setQuerytime(todayString);
		     czjcalService.insertTquerylimit(tquerylimit); 
		}     
		     String todayStr = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		     Map<String, Object> param = new HashMap<String, Object>();
		     param.put("today", todayStr);
		     
		     weatherOrtemperature(cityname, avoidAndSuit, todayStr, param);
		  //   String date = new SimpleDateFormat("yyyy年MM月dd日").format(new Date());
		     avoidAndSuit.setAvoid(avoid);
		     avoidAndSuit.setSuit(suit);
		     avoidAndSuit.setDate(System.currentTimeMillis()+"");
			jsonResult(1,"","获取今天忌宜信息成功",avoidAndSuit,response);
						
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"208","获取今天忌宜信息错误,系统异常","",response);
			log.error("获取今天忌宜信息错误,系统异常",e);
			
		}
		
	}


	public void weatherOrtemperature(String cityname,
			AvoidAndSuit avoidAndSuit, String todayStr,
			Map<String, Object> param) {
		if(cityname==null || "".equals(cityname)){
			cityname="广州市";
		}		
		Map<String, Object> param1 = new HashMap<String, Object>();
		String tstr = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		param1.put("type",cityname);
		param1.put("today", tstr);
		String imgStr = "/weather_icon/g1/d";
		String imgType = ".gif";
		Tquerylimit tquerylimit = czjcalService.getTquerylimitByToday(param1);
		 if(tquerylimit != null){
			 avoidAndSuit.setTemperature(tquerylimit.getTemperature());
			 avoidAndSuit.setWeather(tquerylimit.getWeather());
			 avoidAndSuit.setImgPath(tquerylimit.getExt1());
		 }else{		    	 		     		     
		    //发送 GET 请求 天气
		 String key = StaticMap.weatherKey;	 
		 String weatherStr=HttpRequest.sendGet("http://v.juhe.cn/weather/index", "cityname="+cityname+"&dtype=&format=&key="+key);	
		 Map<String,Object> mapW = JSONObject.parseObject(weatherStr, Map.class);
		 Map<String,Object> mapW1 = (Map<String,Object>)mapW.get("result");
		 Map<String,Object> mapW2 = (Map<String,Object>)mapW1.get("today");
		 String temperature =  (String) mapW2.get("temperature");
		 String weather =  (String) mapW2.get("weather");
		 Map<String, Object>  mapW3 = (Map<String, Object>) mapW2.get("weather_id");
		 String weatherId = (String) mapW3.get("fa");
		 
		 String imgPath = imgStr+weatherId+imgType;
		 
		 tquerylimit = new Tquerylimit();
		 
		 tquerylimit.setType(cityname);
		 tquerylimit.setQuerytime(todayStr);
		 tquerylimit.setCreatetime(new Date());
		 tquerylimit.setTemperature(temperature);
		 tquerylimit.setWeather(weather);
		 tquerylimit.setExt1(imgPath);
		 czjcalService.insertTquerylimit(tquerylimit);
		 avoidAndSuit.setTemperature(temperature);
		 avoidAndSuit.setWeather(weather);
		 avoidAndSuit.setImgPath(imgPath);
		 }		 
	
	}	
		
	
    /***
     * 
     * @author 
     * @date 2017年5月27日 下午2:11:56
     * @param request
     * @param response
     * @param model
     */
	@RequestMapping("dayAvoidAndSuit.do")
	public void detailAvoidDay( HttpServletRequest request, 
			 String cityname,
			String date,
			HttpServletResponse response, ModelMap model) {
		try {
			if("".equals(date) || date == null){
				date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
			}			
			DayAvoidAndSuit dayAvoidAndSuit = new DayAvoidAndSuit();
			  String str= date.substring(0,4);			  
			  String strlast= date.substring(4,date.length());
			  strlast = strlast.replaceAll("0", "");
			  date = str+strlast;		    
		    //发送 GET 请求
			  String key = StaticMap.calendarKey;	 
		     String s=null;	    
		     Map<String,Object> map = null;
		     Map<String,Object> map1 = null;
		     Map<String,Object> map2 = null;
		     String avoid =  null;
		     String suit =  null;
		     String weekday = null;
		     
			    //限制查询忌宜次数一天一次
		        String todayString = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
			    Map<String, Object> paramTquerylimit = new HashMap<String, Object>();
			    paramTquerylimit.put("today", todayString);
			    paramTquerylimit.put("type", "忌宜");
			    Tquerylimit tquerylimit = czjcalService.getTquerylimitByToday(paramTquerylimit);
			    if(tquerylimit!=null){
			    	avoid = tquerylimit.getExt2();
			    	suit = tquerylimit.getExt3();
			    	weekday = tquerylimit.getExt4();
			    }else{			     
		     try {
				      s=HttpRequest.sendGet("http://v.juhe.cn/calendar/day", "date="+date+"&key="+key);	    
				      map = JSONObject.parseObject(s, Map.class);
				      map1 = (Map<String,Object>)map.get("result");
				      map2 = (Map<String,Object>)map1.get("data");
				      avoid =  (String) map2.get("avoid");
				      suit =  (String) map2.get("suit");
				      weekday = (String) map2.get("weekday");			
			} catch (Exception e) {
				avoid ="动土.破土.安葬.治病.";
				suit = "开市.纳财.祭祀.塑绘.安机械.冠笄.会亲友.裁衣.开仓.经络.纳畜.造畜椆栖.教牛马.牧养.";
				weekday="星期一";
			}
		     tquerylimit = new Tquerylimit();
		     tquerylimit.setExt2(avoid);
		     tquerylimit.setExt3(suit);
		     tquerylimit.setExt4(weekday);
		     tquerylimit.setCreatetime(new Date());
		     tquerylimit.setType("忌宜");
		     tquerylimit.setQuerytime(todayString);
		     czjcalService.insertTquerylimit(tquerylimit); 		     
	}     
		     Map<String, Object> param = new HashMap<String, Object>();
		     param.put("date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		     CalTop3 calTop3 = czjcalService.getCalTop1(param);
		     if(calTop3!=null){
					if(calTop3.getFestUrl()!=null){
						calTop3.setImgUrl(calTop3.getFestUrl());
					}
		    	 dayAvoidAndSuit.setFestivalActId(calTop3.getFestivalActId());
		    	 dayAvoidAndSuit.setFestTheme(calTop3.getFestName());
		    	 dayAvoidAndSuit.setSeasonId(calTop3.getSeasonId());
		    	 dayAvoidAndSuit.setImgUrl(calTop3.getImgUrl());

		     }
		        
	           AvoidAndSuit avoidAndSuit = new AvoidAndSuit();
			   String todayStr = new SimpleDateFormat("yyyy-MM-dd").format(new Date());	
			     Map<String, Object> param1 = new HashMap<String, Object>();
			     param1.put("today", todayStr);
		     weatherOrtemperature(cityname, avoidAndSuit, todayStr, param1);
		     
		     dayAvoidAndSuit.setWeather(avoidAndSuit.getWeather());
		     dayAvoidAndSuit.setTemperature(avoidAndSuit.getTemperature());
		     dayAvoidAndSuit.setImgPath(avoidAndSuit.getImgPath());
		     

		     String dateStr = date.substring(5,date.length());
		     dateStr = dateStr.replaceAll("-", "月")+"日";	
		     dayAvoidAndSuit.setWeekday(weekday);
		     dayAvoidAndSuit.setDate(System.currentTimeMillis()+"");
		     dayAvoidAndSuit.setAvoid(avoid);
		     dayAvoidAndSuit.setSuit(suit);

			jsonResult(1,"","获取某天忌宜信息成功",dayAvoidAndSuit,response);
						
		} catch (Exception e) {
			e.printStackTrace();
			jsonResult(0,"208","获取某天忌宜信息错误,系统异常","",response);
			log.error("获取某天忌宜信息错误,系统异常",e);
			
		}
		
	}		
	

	@Resource
	private CzjadvertisementimgService czjadvertisementimgService;
	@Resource
	private Czjadvertisementimg2Service czjadvertisementimg2Service;
	
	@Resource
	private CzjcalService  czjcalService;

	@Resource
	private CzjdiscountService czjdiscountService;
	
	@Resource
	private TroleService troleService;
	
	@Resource
	private TuserService tuserService;
	
	@Resource
	private CzjseasonService czjseasonService;
	
}